package com.alifi.crm.biz.guess;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.common.logging.Logger;
import com.alibaba.common.logging.LoggerFactory;
import com.alifi.crm.dal.guess.EmployeeGuessDAO;

/**
 * 
 * @author wenjing.huangwj
 *
 */
public class ReleaseLockTimeoutTask extends Thread{

	protected static final Logger      logger = LoggerFactory.getLogger(ReleaseLockTimeoutTask.class);	
	private boolean isRunning = true;
	private static final long    DELAY_START_SECONDS = 300;
	
	@Autowired
	private EmployeeGuessDAO employeeGuessDAO;

	public void run() {
		while (isRunning) {
			try{
				sleepSecond(DELAY_START_SECONDS);
			    int count = employeeGuessDAO.releaseLockTimeOut();
			    if(count>0){
			    	logger.info("来解锁了, 解开了 "+count+" 把锁");
			    }else{
			    	logger.info("来解锁了，没找到锁");
			    }
			}
			catch(Exception e){
				logger.error(e);
			}
		}
	}
	
	private void sleepSecond(Long second){
		try {
			Thread.sleep(second*1000);
		} catch (InterruptedException e) {
			throw new SystemException(e);
		}
	}
		
		
}